package me.zhengjie

import me.zhengjie.common.annotation.rest.AnonymousGetMapping
import me.zhengjie.common.utils.SpringContextHolder
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.context.ApplicationPidFileWriter
import org.springframework.context.annotation.Bean
import org.springframework.data.jpa.repository.config.EnableJpaAuditing
import org.springframework.scheduling.annotation.EnableAsync
import org.springframework.transaction.annotation.EnableTransactionManagement
import org.springframework.web.bind.annotation.RestController

@EnableAsync //@EnableOpenApi--swagger3
@RestController
@SpringBootApplication
@EnableTransactionManagement
@EnableJpaAuditing(auditorAwareRef = "auditorAware")
class AppRun
fun main(args: Array<String>) {
	val springApplication = SpringApplication(AppRun::class.java)
	// 监控应用的PID，启动时可指定PID路径：--spring.pid.file=/home/eladmin/app.pid
	// 或者在 application.yml 添加文件路径，方便 kill，kill `cat /home/eladmin/app.pid`
	springApplication.addListeners(ApplicationPidFileWriter())
	springApplication.run(*args)
}

@Bean
fun springContextHolder(): SpringContextHolder {
	return SpringContextHolder()
}

/**
 * 访问首页提示
 *
 * @return /
 */
@AnonymousGetMapping("/")
fun index(): String {
	return "Backend service started successfully"
}

